459B - Pashmak and Flowers - CodeForces Solution


combinatorics implementation sortings *1300

Please click on ads to support us..

Python Code:

n = int(input())
s = input()
l = s.split()
b = []

for i in l:
    b.append(int(i))

b.sort()
print(b[-1] - b[0], end = ' ')


first = 0
last = 0
for i in range(len(b)):
    if b[i] == b[0]:
        first += 1

    if b[i] == b[-1]:
        last += 1


if b[0] == b[-1]:
    print(int(last * (last - 1) / 2))

else:
    print(first * last)

C++ Code:

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    long long n;
    cin >> n;
    vector<int> a(n);
    int high = INT_MIN, low = INT_MAX;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        high = max(high, a[i]);
        low = min(low, a[i]);
    }

    long long cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; i++)
    {
        cnt1 += (a[i] == high);
        cnt2 += (a[i] == low);
    }

    cout << high - low << " ";
    if (high == low)
        cout << n * (n - 1) / 2;
    
    else
        cout << cnt1 * cnt2;
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game